﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GenericValidation
{
    public class ValidationResult
    {
        public bool IsValid { get; set; }
        public string[] ErrorInfo { get; set; }

        public ValidationResult Add(ValidationResult otherResult)
        {
            var errors = new List<string>();
            if (this.ErrorInfo != null)
            {
                errors.AddRange(this.ErrorInfo);
            }

            if (otherResult.ErrorInfo != null)
            {
                errors.AddRange(otherResult.ErrorInfo);
            }

            this.IsValid = this.IsValid && otherResult.IsValid;
            this.ErrorInfo = errors.ToArray();
            return this;
        }

        public override string ToString()
        {
            return string.Format("IsValid:{0} ... {1}",this.IsValid, string.Join(" | ", this.ErrorInfo));
        }
    }
}
